package com.ayg.controller;

import com.ayg.pojo.Cost;
import com.ayg.pojo.Personal;
import com.ayg.service.PersonalService;
import com.ayg.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/personals")
public class PersonalController {

    @Autowired
    private PersonalService personalService;

    /**
     * 添加个人信息
     * @param personal
     * @return
     */
    @PostMapping("/savePersonal")
    public SysResult SavePersonal(@RequestBody Personal personal){
        personalService.SavePersonalInfo(personal);
        return SysResult.success();
    }

    /**
     * 查询信息
     * @return
     */
    @GetMapping("/getTabPersonal")
    public SysResult GetTabPersonal(){
        List<Personal> list=personalService.getTabPersonal();
        return SysResult.success(list);
    }

    /**
     * 删除信息
     * @param id
     * @return
     */
    @DeleteMapping("/deletePersonalById")
    public SysResult deletePersonalById(Integer id){
        personalService.deletePersonalById(id);
        return SysResult.success();
    }

    /**
     * 业务分析: 根据用户ID查询数据库.
     * URL地址: /cost/{costId}
     * 返回值: SysResult对象
     */
    @GetMapping("/{personalName}")
    public SysResult getPersonalById(@PathVariable String personalName){
        Personal personal = personalService.getPersonalById(personalName);
        return SysResult.success(personal);
    }

    /**
     * 修改信息
     * @param personal
     * @return
     */
    @PutMapping("/updateInfoSubmit")
    public SysResult updateInfoSubmit(@RequestBody Personal personal){
        personalService.updateInfo(personal);
        return SysResult.success();
    }

}
